<?php
namespace app\models;
use common\component\tool\Tool;

use Yii;

class AdminRolePriv extends Basic
{
    
    public static function tableName()
    {
        return '{{%admin_role_priv}}';
    }

    public function rules()
    {
        return [
            ['role_id', 'integer', 'message' => 'role_id必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'role_id最小存储0', 
                        'max'=>4294967295, 'tooBig' => 'role_id最大存储4294967295'],
            // ['appid', 'required', 'message' => 'appid不能为空', 'on' => 'add'],
            ['appid', 'string', 'message' => 'appid必须是字符串',
                      'min' => 18, 'tooShort' => 'appid最短18位',
                      'max' => 18, 'tooLong' => 'appid最长18位'],
            ['mid', 'integer', 'message' => 'mid必须为数字，或数字字符串', 
                        'min'=>0, 'tooSmall' => 'mid最小存储0', 
                        'max'=>65535, 'tooBig' => 'mid最大存储65535'],
            // ['apikeyname', 'default', 'value' => ''],
            ['apikeyname', 'string', 'message' => 'apikeyname必须是字符串', 
                           'max' => 64, 'tooLong' => 'apikeyname最长64位'],
            ['m', 'default', 'value' => ''],
            // ['m', 'required', 'message' => 'm不能为空', 'on' => 'add'],
            ['m', 'string', 'message' => 'm必须是字符串',
                      'max' => 32, 'tooLong' => 'm最长32位'],
            // ['c', 'required', 'message' => 'c不能为空', 'on' => 'add'],
            ['c', 'string', 'message' => 'c必须是字符串',
                      'max' => 32, 'tooLong' => 'c最长32位'],
            // ['a', 'required', 'message' => 'a不能为空', 'on' => 'add'],
            ['a', 'string', 'message' => 'a必须是字符串',
                      'max' => 32, 'tooLong' => 'a最长32位'],
            ['args', 'string', 'message' => 'args必须是字符串',
                      'max' => 512, 'tooLong' => 'args最长512位'],
            ['half', 'in', 'range' => array(0, 1), 'message' => 'half值必须在0,1中选择'],
        ];
    }


    /*添加角色*/
    public function addRolePriv($data)
    {
        // P($data);
        // $this->scenario = 'add';
        if($this->load($data) and $this->validate()){
            if($this->save(false)){
                return true;
            }
        }
        return false;
    }

    
}